public class Add {
    public static void main(String[] args) {
        int[] arr = {1, 5, 7, 8};
        int number = 6;
        int[] newArr = add(arr, number); // 接收扩容以后的新数组



        int[] arr2 = {1, 5, 7, 8,6,10,99};
        int number2 = 666;
        int[] newArr2 = add(arr2, number2); // 接收扩容以后的新数组


    }

    public static int[] add(int[] arr, int num) {
        int[] newArr = new int[arr.length + 1]; // 长度+1 新数组
        for (int i = 0; i < newArr.length; i++) {
            if (i < arr.length) {
                newArr[i] = arr[i];
            } else {
                newArr[i] = num;
            }
        }

        for (int i = 0; i < newArr.length; i++) {
            for (int j = i + 1; j < newArr.length; j++) {
                if (newArr[i] > newArr[j]) {
                    int temp = newArr[i];
                    newArr[i] = newArr[j];
                    newArr[j] = temp;
                }
            }
        }
        return newArr;
    }
}
